<!--
 * @Descripttion: 
 * @version: 
 * @Author: gonghong
 * @Date: 2023-06-25 13:59:51
-->

<script setup>
import { ref, reactive } from 'vue'
import { onShow, onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import { getOperatorInfo } from '@/api/system'

//用户信息
const userData = ref({})
//版本号
const version = ref('')
onLoad(async () => {
  const accountInfo = uni.getAccountInfoSync()
  version.value = accountInfo.miniProgram.version
  requestUserInfo()
})
onPullDownRefresh(async () => {
  requestUserInfo()
  uni.stopPullDownRefresh()
})

const requestUserInfo = async () => {
  const result = await getOperatorInfo()
  userData.value = result.data || {}
}
console.log()
/**
 * 跳转到指定页面、做鉴权拦截
 * @param url
 */
const toPage = (url) => {
  //toPageAuth(url)
  uni.navigateTo({ url: url })
}

const handleClickLogOut = async () => {
  uni.showModal({
    title: '提示',
    content: '是否立即退出',
    success: (res) => {
      if (res.confirm) {
        uni.removeStorageSync('accessToken')
        uni.reLaunch({
          url: '/pages/login/index'
        })
      }
    }
  })
}
</script>

<template>
  <view class="swaper">
    <view class="userInfo">
      <image class="avatar" src="../../static/images/default-avatar.png" />
      <view class="userName">
        {{ `${userData.operationName || ''}` }}
      </view>
    </view>
    <uni-list>
      <uni-list-item title="修改密码" showArrow clickable to="/minePages/resetPassword/index" />
      <uni-list-item title="通知公告" showArrow clickable to="/minePages/notice/index" />
      <uni-list-item title="知识库" showArrow clickable to="/minePages/knowledge/index" />
      <uni-list-item title="关于我们" link clickable to="/minePages/aboutUs/index" />
      <uni-list-item title="版本号" :rightText="version" />
      <uni-list-item showArrow title="退出登录" clickable @click="handleClickLogOut" />
    </uni-list>
  </view>
</template>

<style lang="scss" scoped>
.swaper {
  position: absolute;
  width: 100%;
  height: 100%;
  .userInfo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 60upx;
    .avatar {
      width: 112upx;
      height: 112upx;
      margin: auto;
      margin-top: 68upx;
    }
  }
}
.userName {
  font-weight: 400;
  color: #1a1a1a;
  font-size: 28upx;
  margin-top: 20upx;
  min-height: 40upx;
}
</style>
